Imports System.Xml
Imports System.Diagnostics

Partial Class fundies_fstdt
    Inherits System.Web.UI.MasterPage

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        GetCurrentBackground()
    End Sub

    Private Sub GetCurrentBackground()
        GetCurrentBackground(Date.Now)
    End Sub

    Private Sub GetCurrentBackground(ByVal myDate As Date)
        Dim reader As New XmlTextReader(Server.MapPath("~/App_Data/backgrounds.xml"))
        Dim bgcolor As String = "#FFFFFF"
        Const dateTimeFormat As String = "yyyy/MM"
        Do While reader.ReadToFollowing("color")
            Dim testDate As Date
            testDate = Date.Parse(reader.GetAttribute("date"))
            'Debug.WriteLine(testDate.ToString(dateTimeFormat))
            'Debug.WriteLine(myDate.ToString(dateTimeFormat))
            If testDate.ToString(dateTimeFormat) = myDate.ToString(dateTimeFormat) Then
                bgcolor = reader.ReadElementContentAsString
                Exit Do
            End If
        Loop
        reader.Close()

        body.Attributes.Item("bgcolor") = bgcolor
    End Sub
End Class

